/*
 * Ui.cpp
 *
 *  Created on: Jul 6, 2010
 *      Author: bubuntux
 */

#include "Ui.h"
#include <iostream>
using namespace std;

//Just some Default
unsigned int Ui::totalWidth = 800;
unsigned int Ui::totalHeight = 600;

void Ui::initColors() {
	init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); //Header
	init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); //Warning
	init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); //Virus
	init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); //Normal
}

void Ui::printCenter(WINDOW *win, int y, string msg, int color) {
	unsigned int width = getmaxx(win);
	if (msg.length() >= (width - 1)) {
		msg = msg.substr(0, 5) + "..." + msg.substr(
				msg.length() - (width - 10), msg.length());
	}
	string padding(((width - msg.length()) / 2) - 1, ' ');
	attron(COLOR_PAIR(color));
	mvwprintw(win, y, 1, "%s", (padding + msg + padding).c_str());
	attroff(COLOR_PAIR(color));

}

void Ui::printCenter(WINDOW *win, int y, Field field) {
	printCenter(win,y,field.text,field.color);
}
